package com.wxchat.chat.servlet;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.client.utils.URLEncodedUtils;

import com.wxchat.chat.util.WxChatUtils;

@WebServlet("/wxChatServlet")
public class WxChatServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//获取返回的回调的地址
		String str = "http://crmlite.sxsugon.cn/wxchat/callBack";
		//第一步，用户同意授权，获取code
		String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+WxChatUtils.APP_ID
				+ "&redirect_uri="+URLEncoder.encode(str)
				+ "&response_type=code"
				+ "&scope=snsapi_userinfo"
				+ "&state=STATE#wechat_redirect";
		
		//进行重定向
		resp.sendRedirect(url);
		
	}

	
}
